import { httpPost } from './ajax'

/* 根据token获得用户信息 */
export const getInfo = (token: string) => httpPost('/getInfo', token)

/* 注册/登录,根据nickName,contact换/更新token */
type userInfo = {
  nickName: string
  contact?: string
}
export const getToken = (parameter: userInfo) =>
  httpPost('/getToken', parameter)

/* 获得文章列表 */
export const getBlogList = (parameter: { pageNum: number; size: number }) =>
  httpPost('/getBlogList', parameter)

/* 获得文章详情 */
export const getBlogDetail = (parameter: { blogId: number | string }) =>
  httpPost('/getBlogDetail', parameter)

/* 删除文章 */
export const deleteBlog = (parameter: { blogId: number | string }) =>
  httpPost('/deleteBlog', parameter)

type addBlogParams = {
  title: string
  content: string
  cover?: string
}
export const addBlog = (parameter: addBlogParams) =>
  httpPost('/addBlog', parameter)

export const getBlogText = () => httpPost('/getBlogText')
/* 根据文字查询博客,返回博客列表 */
export const queryBlog = (parameter: string) =>
  httpPost('/queryBlog', parameter)

export const addViewCount = () => httpPost('/addViewCount')
type addCommentParams = {
  content: string
  id: number | string
}
/* 添加评论 */
export const addComment = (parameter: addCommentParams) =>
  httpPost('/addComment', parameter)
/* 查询所有评论 */
export const queryComment = (parameter: { pageNum: number; size: number }) =>
  httpPost('/queryComment', parameter)

/* 删除评论 */
export const deleteComment = (parameter: number[]) =>
  httpPost('/deleteComment', parameter)

/* 删除评论回复 */
export const deleteCommentReply = (parameter: {
  blogId: number | string
  commentId: number
}) => httpPost('/deleteCommentReply', parameter)
/* 添加评论回复 */
export const addCommentReply = (parameter: {
  blogId: number | string
  commentId: number
  reply: string
}) => httpPost('/addCommentReply', parameter)

/* 查询新评论数量 */
export const getTotalCommentStatus = () => httpPost('/getTotalCommentStatus')
